package calvin.study.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import calvin.study.redis.service.IRedPacketService;

@RestController
@RequestMapping("/redPacket")
public class RedPacketController {
	@Autowired
	private IRedPacketService redPacketService;

	@GetMapping("/send/{userId}/{money}/{nums}")
	public String send(@PathVariable String userId,@PathVariable int money, @PathVariable int nums) {
		try {
			boolean flag = redPacketService.sendRedPacket(userId,money, nums);
			if (!flag) {
				return "发送红包失败！";
			}
		} catch (Exception e) {
			return "发送红包失败！";
		}
		return "发送红包成功！";
	}
	
	@GetMapping("/getRedPacket/{userId}/{groupId}")
	public String getRedPacket(@PathVariable String userId,@PathVariable String groupId) {
		Integer getRedPacket = null;
		try {
			 getRedPacket = redPacketService.getRedPacket(userId, groupId);
		} catch (Exception e) {
			return e.getMessage();
		}
		return String.valueOf(getRedPacket);
	}

}
